import regularList from "../config/regular-config";
// 正则方法对象
const checkInput = {

};

/**
 * 循环配置添加正则方法
 * 1.结构规则配置
 * 2.多规则循环校验
 * 3.返回校验结果
 */
for (let key in regularList) {
    const [list, msg] = regularList[key];
    checkInput[key] = (rule, value, callback) => {
        if (!value) {
            callback();
            return true;
        }
        const isNext = [];
        list.forEach(regular => (isNext.push(regular.test(value))));
        if (!isNext.some(isOk => (isOk))) {
            callback(msg);
            return false
        }
        callback();
        return true;
    }
}
export default checkInput;
